#include <iostream>
#include <vector>
#include <ctime>
#include <random>

using namespace std;

void insertSort(vector<int> &vec)
{
    for (int i = 1; i < vec.size(); i++)
    {
        int tmp = vec[i];
        while (i >= 0 && vec[i - 1] > tmp)
        {
            vec[i] = vec[i - 1];
            i--;
        }
        vec[i] = tmp;
    } 
}

int main(int argc, char const *argv[])
{
    srand(time(NULL));
    vector<int> vec(50);
    for (int i = 0; i < 50; i++)
        vec[i] = rand() % 100 + 1;
    cout << "排序前：" << endl;
    for (auto ele : vec)
        cout << ele << ",";
    cout << endl;
    insertSort(vec);
    cout << "排序后：" << endl;
    for (int &ele : vec)
        cout << ele << ",";
    return 0;
}
